package com.yuanduan.mplus.view;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cj.framework.app.BaseActivity;
import com.yuanduan.mplus.R;
import com.yuanduan.mplus.config.Config;
import com.yuanduan.mplus.presenter.ReportAdapter;

import java.util.ArrayList;
import java.util.List;

import static com.yuanduan.mplus.R.id.report_viewPager;

/**
 * 废弃
 */
public class ReportActivity extends BaseActivity implements View.OnClickListener {
    private TextView tv_title;
    private ImageView iv_back;
    private TabLayout tabLayout;
    private ViewPager viewPager;

    private ReportAdapter reportAdapter;

    public  String reportType;
    public String Type;
    public String Choose;
    private List<Fragment> datalists =new ArrayList<Fragment>();
    private List<String> titlelists=new ArrayList<String>();
    @Override
    protected void findId() {
        tv_title= (TextView) findViewById(R.id.report_title);
        iv_back= (ImageView) findViewById(R.id.report_back);
        tabLayout= (TabLayout) findViewById(R.id.report_tabLayout);
        viewPager= (ViewPager) findViewById(report_viewPager);
    }

    @Override
    protected void logic() {
        //设置标题，设置tablayout
        Choose=getIntent().getStringExtra("Choose");
        Type=getIntent().getStringExtra("Type");
        if(Config.userType==1){
            //刷新tablayout字段，更新title
            reportType=getIntent().getStringExtra("reportType");
            tv_title.setText(reportType);

        }else if(Config.userType==2){
            Bundle bundle=getIntent().getExtras();
            reportType=getIntent().getStringExtra("reportType");
            tv_title.setText(bundle.getString("RealName")+"的"+reportType);
        }else{

        }

        reportAdapter=new ReportAdapter(getSupportFragmentManager());
        ReportFragment_1 reportFragment_1=new ReportFragment_1();
        ReportFragment_2 reportFragment_2=new ReportFragment_2();
        datalists.add(reportFragment_1);
        datalists.add(reportFragment_2);
        reportAdapter.setData(datalists);
        titlelists.add(reportType+"报表");
        titlelists.add(reportType+"介绍");
        reportAdapter.setTitles(titlelists);
        viewPager.setAdapter(reportAdapter);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setupWithViewPager(viewPager);

        iv_back.setOnClickListener(this);
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_report;
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.report_back:
                this.finish();
                break;
        }
    }
}
